package com.zxh.blog.service.impl;

import com.zxh.blog.dao.PermissionDao;
import com.zxh.blog.dao.RoleDao;
import com.zxh.blog.domain.Permission;
import com.zxh.blog.domain.Role;
import com.zxh.blog.domain.User;
import com.zxh.blog.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

	@Autowired
	RoleDao roleDao;

	@Autowired
	PermissionDao permissionDao;

	public Role findRoleByUser(User user) {
		Role role = roleDao.findRoleByPrimaryKey(user.getId());
		return role;
	}

	public List<Role> selectByList() {
		List<Role> roles = roleDao.selectByList();
		return roles;
	}

	public List<Permission> findPermissionByRoleId(Integer roleId) {
		List<Permission> permissions = permissionDao.findPermissionsByRoleId(roleId);
		return permissions;
	}

	public Integer addRole(Role role) {
		Integer integer = roleDao.addRole(role);
		return integer;
	}

	public void updateRole(Role role) {
		roleDao.updateRole(role);
	}

	public void deleteByIds(int[] ids) {
		roleDao.deleteByIds(ids);
	}

	public Integer insertRolePermission(Integer roleId, Integer permissionId) {
		Integer insert = roleDao.insertRolePermission(roleId, permissionId);
		return insert;
	}

	public void deletePerByRoleId(int roleId) {
		roleDao.deletePerByRoleId(roleId);
	}

}
